API Documentation for: 1.1.23
Show:

Button (PIXI) Class

Extends PIXI.DisplayObjectContainer
Defined in: Button (PIXI):8
Namespace: cloudkid

A Multipurpose button class. It is designed to have one image, and an optional text label. The button can be a normal button or a selectable button. The button functions similarly with both CreateJS and PIXI, but slightly differently in initialization and callbacks. Use releaseCallback and overCallback to know about button clicks and mouse overs, respectively.

Constructor

Button (PIXI)

(
  • [imageSettings]
  • [label=null]
  • [enabled=true]
)

Defined in Button (PIXI):8

Parameters:

  • [imageSettings] Object optional

    Information about the art to be used for button states, as well as if the button is selectable or not.

    • [priority=null] Array optional

      The state priority order. If omitted, defaults to ["disabled", "down", "over", "up"]. Previous versions of Button used a hard coded order: ["highlighted", "disabled", "down", "over", "selected", "up"].

    • [up] Object | PIXI.Texture optional

      The texture for the up state of the button. This can be either the texture itself, or an object with 'tex' and 'label' properties.

      • [tex] PIXI.Texture optional
        The sourceRect for the state within the image.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
    • [over=null] Object | PIXI.Texture optional

      The texture for the over state of the button. If omitted, uses the up state.

      • [tex] PIXI.Texture optional
        The sourceRect for the state within the image.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
    • [down=null] Object | PIXI.Texture optional

      The texture for the down state of the button. If omitted, uses the up state.

      • [tex] PIXI.Texture optional
        The sourceRect for the state within the image.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
    • [disabled=null] Object | PIXI.Texture optional

      The texture for the disabled state of the button. If omitted, uses the up state.

      • [tex] PIXI.Texture optional
        The sourceRect for the state within the image.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
    • [<yourCustomState>=null] Object | PIXI.Texture optional

      The visual information about a custom state found in imageSettings.priority. Any state added this way has a property of the same name added to the button. Examples of previous states that have been moved to this system are "selected" and "highlighted".

      • [tex] PIXI.Texture optional
        The texture for the custom state.
      • [label=null] Object optional
        Label information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" from the label parameter may be overridden.
    • [origin=null] PIXI.Point optional

      An optional offset for all button graphics, in case you want button positioning to not include a highlight glow, or any other reason you would want to offset the button art and label.

    • [scale=1] Number optional

      The scale to use for the textures. This allows smaller art assets than the designed size to be used.

  • [label=null] Object optional

    Information about the text label on the button. Omitting this makes the button not use a label.

    • [type] String optional

      If label.type is "bitmap", then a PIXI.BitmapText text is created, otherwise a PIXI.Text is created for the label.

    • [text] String optional

      The text to display on the label.

    • [style] Object optional

      The style of the text field, in the format that PIXI.BitmapText and PIXI.Text expect.

    • [x="center"] String | Number optional

      An x position to place the label text at relative to the button.

    • [y="center"] String | Number optional

      A y position to place the label text at relative to the button. If omitted, "center" is used, which attempts to vertically center the label on the button.

  • [enabled=true] Boolean optional

    Whether or not the button is initially enabled.

Methods

_addProperty

(
  • propertyName
)
private

Defined in _addProperty:474

Adds a property to the button. Setting the property sets the value in _stateFlags and calls _updateState().

Parameters:

  • propertyName String

    The property name to add to the button.

_onDown

() private

Defined in _onDown:606

The callback for when the button receives a mouse down event.

_onOut

() private

Defined in _onOut:593

The callback for when the mouse leaves the button area.

_onOver

() private

Defined in _onOver:580

The callback for when the button is moused over.

_onUp

() private

Defined in _onUp:621

The callback for when the button for when the mouse/touch is released on the button

  • only when the button was held down initially.

_onUpOutside

() private

Defined in _onUpOutside:639

The callback for when the mouse/touch is released outside the button when the button was held down.

initialize

(
  • [imageSettings]
  • [label=null]
  • [enabled=true]
)

Defined in initialize:208

Constructor for the button when using PIXI.

Parameters:

  • [imageSettings] Object optional

    Information about the art to be used for button states, as well as if the button is selectable or not.

  • [label=null] Object optional

    Information about the text label on the button. Omitting this makes the button not use a label.

  • [enabled=true] Boolean optional

    Whether or not the button is initially enabled.

Properties

_currentLabelStyle

Object private

The current style for the label, to avoid setting this if it is unchanged.

_offset

PIXI.Point private

Defined in _offset:136

An offset to button positioning, generally used to adjust for a highlight around the button.

_stateData

Object private

Defined in _stateData:120

A dictionary of state graphic data, keyed by state name. Each object contains the sourceRect (src) and optionally 'trim', another Rectangle. Additionally, each object will contain a 'label' object if the button has a text label.

_stateFlags

Object private

Defined in _stateFlags:106

A dictionary of state booleans, keyed by state name.

_statePriority

Array private

Defined in _statePriority:112

An array of state names (Strings), in their order of priority. The standard order previously was ["highlighted", "disabled", "down", "over", "selected", "up"].

_upOutCB

Function private

Defined in _upOutCB:172

Callback for mouse up outside, bound to this button.

outCallback

Function public

Defined in outCallback:99

The function that should be called when mouse leaves the button.

overCallback

Function public

Defined in overCallback:92

The function that should be called when the button is moused over.

releaseCallback

Function public

Defined in releaseCallback:85

The function that should be called when the button is released.